﻿#region License statement
// NJamb, a specification and delta-specification DSL
// Copyright (c) 2010-2011, Mark Knell
// Published under the MIT License; all other rights reserved
#endregion

#region using...
using System;
using System.Collections.Generic;
using NJamb.Parser.SpecificationBuilders.SubjectHas.AbstractEnumerable;
using NJamb.Parser.SpecificationBuilders.SubjectHas.Simple.Enumerable;
using NJamb.Parser.SpecificationBuilders.SubjectIs.Simple.Enumerable;
using NJamb.Specifications.Simple.Enumerable;
using Stile.Patterns.SelfDescribingPredicates;
#endregion

namespace NJamb.Parser.Subjects.Enumerable
{
    public class EnumerableSubject<TSubject, TItem> :
        Subject
            <TSubject, IEnumerableHas<TSubject, TItem, IEnumerableSpecification<TSubject, TItem>>,
                INegatableEnumerableIs<TSubject, TItem>, IEnumerableSpecification<TSubject, TItem>>,
        IEnumerableSubject<TSubject, TItem>
        where TSubject : class, IEnumerable<TItem>
    {
        public EnumerableSubject(Func<TSubject> getter, Lazy<string> lazyDescription)
            : base(getter, lazyDescription) {}

        public override IEnumerableSpecification<TSubject, TItem> Specify(
            ISelfDescribingPredicate<TSubject> selfDescribingPredicate,
            Func<Exception, TSubject, IEvaluation<TSubject>> exceptionFilter = null)
        {
            return new EnumerableSpecification<TSubject, TItem>(this, selfDescribingPredicate, exceptionFilter : exceptionFilter);
        }

        protected override IEnumerableHas<TSubject, TItem, IEnumerableSpecification<TSubject, TItem>> MakeHas()
        {
            return new EnumerableHas<TSubject, TItem>(this);
        }

        protected override INegatableEnumerableIs<TSubject, TItem> MakeIs()
        {
            return new NegatableEnumerableIs<TSubject, TItem>(this, Negated.False);
        }
    }
}
